import moment from 'moment';

const option = {
  menuPosition: 'right',
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '时间范围',
      span: 8,
      prop: 'examineDate',
      type: 'datetimerange',
      format: 'yyyy-MM-dd HH:mm',
      valueFormat: 'yyyy-MM-dd HH:mm',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() || moment(time).format('yyyy-MM-DD') === moment(new Date()).format('yyyy-MM-DD');
        }
      },
      rules: [
        {
          required: true,
          message: '请选择时间范围',
          trigger: 'blur'
        },
        {
          trigger: 'change',
          validator: (rule, value, callback) => {
            const endTime = moment(value[1]).format('yyyy-MM-DD HH:MM:SS');
            const startTime = moment(value[0]).format('yyyy-MM-DD HH:MM:SS');
            if (!startTime.isSame(endTime, 'day')) {
              callback(new Error('查询日期范围最多选择一天'));
            }
            if (endTime.diff(startTime, 'seconds') < 60) {
              callback(new Error('查询日期范围最少选择一分钟'));
            }
            callback();
          }
        }
      ]
    },
    {
      label: '',
      prop: 'btn',
      span: 10,
      formslot: true
    }
  ]
};

function generateTimeArray() {
  let timeArray = [];
  let currentTime = moment().startOf('day');
  for (let i = 0; i < 8640; i++) {
    let timeString = currentTime;
    timeArray.push(timeString.format('HH:mm:ss'));
    currentTime.add(10, 'seconds');
  }
  return timeArray;
}
const xAixsData = generateTimeArray();

function generateRandomArray() {
  console.log(1);
  let randomArray = new Array(8640).fill(0).map(() => Math.floor(Math.random() * 100));
  return randomArray;
}
const seriesData = generateRandomArray();
const currentChartOption = {
  tooltip: {
    trigger: 'axis'
  },
  axisPointer: {
    snap: true,
    lineStyle: {
      color: 'rgb(96, 98, 102)',
      type: 'dashed',
      width: 2
    }
  },
  title: {
    left: 'center',
    text: '点焊机电流瞬时连续值趋势图'
  },
  yAxis: {
    name: '电流/A',
    show: true,
    type: 'value'
  },
  xAxis: {
    name: '时间',
    data: xAixsData,
    show: true
  },
  dataZoom: [
    {
      type: 'inside',
      start: 0,
      end: 20
    },
    {
      start: 0,
      end: 20
    }
  ],
  series: {
    name: '电流值:',
    type: 'line',
    smooth: true,
    data: seriesData,
    itemStyle: {
      normal: {
        color: '#10acf1', //改变折线点的颜色
        lineStyle: {
          color: '#10acf1' //改变折线颜色
        }
      }
    }
  }
};

const voltageChartOption = {
  tooltip: {
    trigger: 'axis'
  },
  lineStyle: {
    color: 'rgb(96, 98, 102)',
    type: 'dashed',
    width: 2
  },
  title: {
    left: 'center',
    text: '点焊机电压瞬时连续值趋势图'
  },
  yAxis: {
    name: '电压/V',
    show: true,
    type: 'value'
  },
  xAxis: {
    name: '时间',
    data: xAixsData,
    show: true
  },
  dataZoom: [
    {
      type: 'inside',
      start: 0,
      end: 20
    },
    {
      start: 0,
      end: 20
    }
  ],
  series: {
    name: '电压值:',
    type: 'line',
    smooth: true,
    data: seriesData,
    itemStyle: {
      normal: {
        color: '#f59a23', //改变折线点的颜色
        lineStyle: {
          color: '#f59a23' //改变折线颜色
        }
      }
    }
  }
};

export { option, voltageChartOption, currentChartOption };
